/**
 * 
 */
var functionpoint = {
	id : 'functionpoint-panel',
	title : '业务功能视图',
	layout : 'border',
	defaults : {
		
		bodyStyle : 'padding:15px'
	},
	items : [  {
	    tbar: [{xtype:'button',width:50,text:'返回',iconCls: 'return',handler:returnToProcess}],
		region : 'center',
		border : false,
		

		autoScroll:true,
		contentEl : 'functionCanvas'

	} ]
};
function returnToProcess(){
	if (pid=='-1'&& pText=='-1') {
		Ext.getCmp('content-panel').layout.setActiveItem('function-list-panel');
		  showFunctionList();
	}
	else {  
	  Ext.getCmp('content-panel').layout.setActiveItem('process-panel');
	  showProcessContent(pid,pText);}
}
var parameterStore = new Ext.data.Store({
	proxy : new Ext.data.HttpProxy({
		url : 'showParameter.action?method=showParameter',
		method : 'post'
	}),
	reader : new Ext.data.JsonReader({
		root : "parameter",
		totalProperty : "totalParameter",
		id:"id"
    }, [ {
		name : 'id'
	}, {
		name : 'enName'
	},{
		name : 'cnName'
	},{
		name : 'description'
	},{
		name : 'inOutType'
	}, {
		name : 'isBuiltIn'
	}, {
		name : 'paramTypeId'
	}, {
		name : 'paramTypeName'
	}, {
		name : 'functionPointId'
	}, {
		name : 'collectionType'
	}, {
		name : 'restrictions'
	}])
});
var pid;
var pText;
function showFunctionContent(cid,text,processid,processText) {
   
    
    pid=processid;
    pText=processText;
    parameterStore.load({ 
    	params : {
			cid : cid
		},
		callback: function(r, options, success) { 
		if (success == false) {  
		alert("加载数据失败，无对应数据或者系统出现异常！"); 
		}else{ 
			var canvas=document.getElementById('functionCanvas');
			var ctx=canvas.getContext('2d');
			 drawFunctionModel(300,300,ctx,parameterStore,text);
			}
		}
		});

		
	  
}
function drawFunctionModel(startx,starty,ctx,parameterStore,text){
	 ctx.restore();
	 ctx.clearRect(0, 0, 800, 800);
	 ctx.save();
	 ctx.translate(startx, starty);
	 var pAmount=parameterStore.getCount();
	 var length=(pAmount+1)*20; //function视图长度
	 
     var gradient = ctx.createLinearGradient(0, 0, 0, length);
	 gradient.addColorStop(0, 'rgb(154, 205, 50)');
	 gradient.addColorStop(1, 'rgb(255,255,240)');
	 ctx.fillStyle = gradient;
	 ctx.fillRect( 0, 0, 200, length); //渐变的背景色
	 
	 ctx.strokeStyle = '#000000'; 
	 ctx.beginPath(); 
	 ctx.rect(0.5,0.5, 200, length);
	 ctx.stroke();              //黑边框
	 
	 var functionImage=new Image();
	 functionImage.onload=function(){
	 ctx.drawImage(functionImage,3,2,16,16);
	 };
	 functionImage.src='images/modelUnit/function/function_name.gif';
	 
	 ctx.fillStyle ="black";
	 ctx.font = "10pt Arial";
	 ctx.fillText(text,25,16,175); //标题栏
	 
	 
	 
	 ctx.beginPath();
	 ctx.moveTo(0,20);
	 ctx.lineTo(200,20);
	 ctx.stroke();   
	 ctx.beginPath();
	 ctx.moveTo(0.5,20.5);
	 ctx.lineTo(200.5,20.5);
	 ctx.stroke();        //画分割线
	 
	 

	 var inputImg=new Image();
	 inputImg.onload=function(){
		 var outputImg=new Image();
		 outputImg.onload=function(){
			 var inoutputImg=new Image();
			 inoutputImg.onload=function(){
     for (var i=0;i<pAmount;i++){
    	 var record=parameterStore.getAt(i);	
    	 if (record.get('inOutType')=='input')
			ctx.drawImage(inputImg,3,22+i*20,16,16);
    	 else if (record.get('inOutType')=='output')
 			ctx.drawImage(outputImg,3,22+i*20,16,16);
    	 else ctx.drawImage(inoutputImg,3,22+i*20,16,16);
			ctx.fillStyle ="black";
			ctx.font = "10pt Arial";
			ctx.fillText('['+record.get('cnName')+']'+record.get('enName'),22,36+i*20,175); //参数栏
		 }
			 };
	 inoutputImg.src='images/modelUnit/function/inoutput.gif';
	 };
	 outputImg.src='images/modelUnit/function/output.gif';
	 };
	 inputImg.src='images/modelUnit/function/input.gif';
	 
	
	 var parameterImage=new Image();
		 parameterImage.onload=function(){
			 var parameterInfo=new Image();
	  		 parameterInfo.onload=function(){
	 for (var i=0;i<pAmount;i++)
	 {
		 x=parseInt(-250*Math.cos(i*Math.PI*2/pAmount));
  	     if (x>200) x=1.1*x;
  	     y=parseInt(-250*Math.sin(i*Math.PI*2/pAmount));
  	     gradient = ctx.createLinearGradient(x, y, 0, 100);
  		 gradient.addColorStop(0, 'rgb(230, 230, 250)');
  		 gradient.addColorStop(1, 'rgb(255,255,240)');
  		 ctx.fillStyle = gradient;
  		 ctx.fillRect( x, y, 200, 100); //渐变的背景色
  		
  		 ctx.lineWidth = 1;
  		 ctx.strokeStyle = '#000000'; 
  		 ctx.beginPath(); 
  		
  		 ctx.rect(x-0.5,y-0.5, 200, 100);
  		 ctx.stroke();              //黑边框
  		 
  		 
  		
  		 ctx.drawImage(parameterImage,x+3,y+2,16,16);
  		
  		 ctx.fillStyle ="black";
  		 ctx.font = "10pt Arial";
  		 ctx.fillText(parameterStore.getAt(i).get('cnName'),x+25,y+16,175); //标题栏
  		 
  		 ctx.beginPath();
  		 ctx.moveTo(x,y+20);
  		 ctx.lineTo(x+200,y+20);
  		 ctx.stroke();
  		 
  		 ctx.beginPath();
  		 ctx.moveTo(x+0.5,y+20.5);
  		 ctx.lineTo(x+200.5,y+20.5);
  		 ctx.stroke();        //画分割线
  		 
  		
  			 for (var j=0;j<4;j++){
  				 ctx.drawImage(parameterInfo,x+3,y+22+j*20,16,16);
  			 }
  		
		 ctx.fillStyle ="black";
  		 ctx.font = "10pt Arial";
		 ctx.fillText('输入输出：'+parameterStore.getAt(i).get('inOutType'),x+22,y+36,175);
		 ctx.fillText('内建类型：'+parameterStore.getAt(i).get('isBuiltIn'),x+22,y+56,175);
		 ctx.fillText('参数类型：'+parameterStore.getAt(i).get('paramTypeName'),x+22,y+76,175);
		 ctx.fillText('集合类型：'+parameterStore.getAt(i).get('collectionType'),x+22,y+96,175);
		 drawLine(x+100,y+50,100,length/2,ctx,200,100);
	 	 }
	  		 };
			 parameterInfo.src='images/modelUnit/function/parameter_info.gif';
		 };
  		 parameterImage.src='images/modelUnit/function/parameter_name.gif';
	
}
